<template>
	<view>
		<view class="head_box">
			<sh-filter @change="onFilter" @onConfirm="hanleSort" :dicData="dicData" @onSearch="handleSearch" :perData="personData" @onRanking='handleRanking' :sortList='sortList'></sh-filter>
		</view>
		<view class="content-box">
			<list-item :dataList="listData" :showCheckBox="showChk" @getIndex="getIndex" />
		</view>
		<mix-float-menu 
			@onBtnClick="clickFloatBtn" 
			@onClose="close" 
			@add="addNewPage"
			@onFinish="handleFinish"
			@onDelete="handleDelete"
			@onExport="handleExport"
			@onPause="handlePause"
			@sendWritten="sendWrit" 
			:isShow="showItem" ref="child">
		</mix-float-menu>
		<mix-export :selectIds="selectIds" :queryString="queryString" @onClose="closeExport" :show="showExport"></mix-export>
	</view>
</template>

<script>
	import shFilter from '../pulic/sh-filter.vue';
	import listItem from './components/listItem.vue';
	import mixFloatMenu from '../../components/mix-float-menu.vue';
	import mixExport from '../../components/mix-export.vue';
	export default {
		components: {
			listItem,
			shFilter,
			mixFloatMenu,
			mixExport
		},
		data() {
		    return{
				sortFieldData:{
					sortField:'', //字段名称
					sortOrder:'',//排序方式
				},
				sortList:[
					{
						sortField:'CREATE_TIME', //字段名称
						sortOrder:'',//排序方式
						title:'入库日期',  //字段名称
					},
					{
						sortField:'EVALUATE',
						sortOrder:'',//排序方式
						title:'项目星级',
					},
					{
						sortField:'EXPECT_INVEST',
						sortOrder:'',//排序方式
						title:'投资额',
					},
					{
						sortField:'PROJ_START_UP',
						sortOrder:'',//排序方式
						title:'启动时间',
					},
					{
						sortField:'MANAGER_NAME',
						sortOrder:'',//排序方式
						title:'跟进负责人',
					}
				],
				listData:[],
				personData:[],
				pageNumber:1,
				moreTip:false,
				showItem:'new,handle,delete,export,cancle,written',
				actIndex: null,
				moduleId:'busProjManage',
				modalName:'',
				reportType:"1",
				showmenu:false,
				showChk:false,
				dicData:{},
				formData: {
					searchText : ''
				},
				queryString:'',
				selectIds:'',
				showExport:false
			}
		},
		
		methods: {
			reset(){
				this.actIndex=null
				this.showmenu=false
				this.showChk=false
				this.$refs.child.handleClose()
			},
			onFilter(e) {
				this.goodsList = [];
				this.listParams.page = 1;
			},
			handleRanking(data){
				this.sortList.forEach((item, index) => {
					if(data!==index){
						item.sortOrder=''
					}
				})
				if(this.sortList[data].sortOrder){
					if(this.sortList[data].sortOrder==='asc'){
						this.sortList[data].sortOrder='desc'
					}else{
						this.sortList[data].sortOrder='asc'
					}	
				}else{
					this.sortList[data].sortOrder='asc'
				}
				this.sortFieldData={
					sortField:this.sortList[data].sortField, //字段名称
					sortOrder:this.sortList[data].sortOrder,//排序方式
				}
				this.getDataList()
			},
			hanleSort(e) {
				console.log('sort',e)
				this.formData= {
					searchText : ''
				}
				const formsData = {...e,...this.formData};
				this.reset()
				formsData.searchText = '';
				this.formData = formsData;
				this.getDataList()
			},
			handleSearch(e){
				console.log('search',e)
				this.reset()
				if(e){
					this.formData.searchText = e;
				}else{
					this.formData.searchText = ''
				}
				
				this.getDataList()
			},
			//点击悬浮按钮
			clickFloatBtn() {
				this.showChk = true
			},
			//点击新建项目
			addNewPage(){
				const path = `/pages/projectManerge/edit/newset`
				uni.navigateTo({
					url:path
				})
			},
			//点击办结
			async handleFinish() {
				if (this.actIndex == null) {
					uni.showToast({
						title: "请选择一条数据",
						icon: "none"
					})
					return;
				}
				const datakey = this.listData[this.actIndex].DATAKEY;
				const auth = this.listData[this.actIndex].AUTH;
				const status = this.listData[this.actIndex].PROJ_STATUS;
				console.log(auth, status)
				if (auth == 1 && status != 4) {
					uni.showLoading({
			
					})
					const res = await this.$req({
						url: 'bus/proj/doGetThrough.do',
						data: {
							selectedIds: datakey
						}
					})
					uni.hideLoading()
					if (res.data.success) {
						uni.showToast({
							title: '操作成功'
						})
						this.reset();
						this.getDataList();
					} else {
						uni.showToast({
							title: ret.data.messages[0].content
						})
					}
				} else {
					uni.showToast({
						title: '没有权限操作',
						icon: 'none'
					})
				}
			
			},
			//点击删除
			handleDelete() {
				const self = this;
				if (this.actIndex == null) {
					uni.showToast({
						title: "请选择一条数据",
						icon: "none"
					})
					return;
				}
				const datakey = this.listData[this.actIndex].DATAKEY;
				const auth = this.listData[this.actIndex].AUTH;
				const status = this.listData[this.actIndex].PROJ_STATUS;
				uni.showModal({
					title: '确定删除吗?',
					async success(e) {
						if (e.confirm) {
							uni.showLoading({
			
							})
							const res = await self.$req({
								url: 'bus/projmanage/remove.do',
								data: {
									selectedIds: datakey
								}
							})
							uni.hideLoading()
							if (res.data.success) {
								uni.showToast({
									title: '操作成功'
								})
								self.reset();
								self.getDataList();
							} else {
								uni.showToast({
									title: res.data.messages[0].content,
									icon: 'none'
								})
							}
						}
					}
				})
			},
			//导出
			 handleExport() {
				 if (this.actIndex == null) {
				 	uni.showToast({
				 		title: "请选择一条数据",
				 		icon: "none"
				 	})
				 	return;
				 }
				this.showExport = true;
				console.log('this.actins',this.actIndex)
				if(this.actIndex != null){
					const datakey = this.listData[this.actIndex].DATAKEY;
					const auth = this.listData[this.actIndex].AUTH;
					const status = this.listData[this.actIndex].PROJ_STATUS;
					this.selectIds = datakey;
					console.log('this.selectIds===',this.selectIds)
				}
				
				
			},
			closeExport(){
				this.showExport = false
			},
			async handlePause() {
				if (this.actIndex == null) {
					uni.showToast({
						title: "请选择一条数据",
						icon: "none"
					})
					return;
				}
				const datakey = this.listData[this.actIndex].DATAKEY;
				const auth = this.listData[this.actIndex].AUTH;
				const status = this.listData[this.actIndex].PROJ_STATUS;
				console.log(auth, status)
				if (auth == 1) {
					uni.showLoading({
			
					})
					const res = await this.$req({
						url: 'bus/proj/isRepeiee.do',
						data: {
							selectedIds: datakey
						}
					})
					uni.hideLoading()
					if (res.data.success) {
						uni.showToast({
							title: '操作成功'
						})
						this.reset();
						this.getDataList();
					} else {
						uni.showToast({
							title: ret.data.messages[0].content
						})
					}
				} else {
					uni.showToast({
						title: '没有权限操作',
						icon: 'none'
					})
				}
			
			},
			//点击关闭
			close() {
				this.showChk = false;
			},
			showModal(){
				console.log(this.actIndex)
				if(this.actIndex == null){
					uni.showToast({
						title:"请选择一条数据",
						icon:"none"
					})
					return;
				}
				this.modalName = this.listData[this.actIndex].NAME
				this.$refs.popup.open()
			},
			send(){
				console.log(this.actIndex)
				
				if(this.actIndex == null){
					uni.showToast({
						title:"请选择一条数据",
						icon:"none"
					})
					return;
				}
				const datekey = this.listData[this.actIndex].DATAKEY
				const projId = this.listData[this.actIndex].PROJ_ID
				uni.navigateTo({
					url:`../submitReport/submitReport?dataKey=${datekey}&projId=${projId}`
				})
			},
			//点击新建批示
			sendWrit(){
				if(this.actIndex == null){
					uni.showToast({
						title:"请选择一条数据",
						icon:"none"
					})
					return;
				}
				const projectName = this.listData[this.actIndex].NAME
				const projectId = this.listData[this.actIndex].PROJ_ID
				uni.navigateTo({
					
					url:`/pages/readInformation/add?projectId=${projectId}&projectName=${projectName}`
				})
			},
			
			getIndex(e) {
				console.log('e', e.index)
				this.actIndex = e.index
			},
			// 路由跳转
			navToPage() {
				uni.navigateTo({
					url: `/pages/projectStorage/projectStorage`
				})
			},
			
		
			async getDataList(){
				uni.showLoading()
				const dicData = JSON.parse(uni.getStorageSync('dicData'));
				this.dicData=dicData
				const ret = await this.$req({
					url: `bus/proj/filter.do`,
					data: {
						moduleId: 'busProj'
					}
				})
				let personData = {}
				if (ret.data.success) {
					this.personData = ret.data.attributes.zdyDataSource.personDataSourceManage
				}
				const basicParams ={
					pageSize: "10", //每页条数
					pageNo: this.pageNumber, //页码
					moduleId: 'busProj'//固定值
				}
				const params = {...this.formData,...basicParams,...this.sortFieldData}
				if(params.MANAGER==''){
					delete params.MANAGER
				}
				//列表
				const res  = await this.$req({
					url:`bus/proj/ajaxSearch.do`,
					data: params
				})
				uni.hideLoading()
				if(res.data.success){
					const list = this.listData;
					const rows = [...res.data.attributes.rows]
					this.queryString = res.data.attributes.queryString;
					rows.forEach(item=>{
						item.industry = item.INDUSTRY ? this.$util.queryDicName(dicData,'inve_field', item.INDUSTRY) : ''
						item.star =parseInt(item.EVALUATE)+1
						item.createTime = item.CREATE_TIME ? item.CREATE_TIME.split(' ')[0] : ''
						//用地方式
						item.placeUsingType = item.SITE_TYPE ? this.$util.queryDicName(dicData,'busProjSiteMethod', item.SITE_TYPE) : '' 
						//项目状态
						item.proState = item.PROJ_STATUS ? this.$util.queryDicName(dicData,'busProjStatus', item.PROJ_STATUS) : ''
						//项目
						//跟进人
						item.followPerson = this.$util.queryPersonName(item.MANAGER, personData)
						//项目阶段
						item.proStep = item.PROJ_STAGE ? this.$util.queryDicName(dicData,'busProjStage', item.PROJ_STAGE) : '' 
					})
					let newArr = [];
					newArr = this.pageNumber <=1 ? rows : list.concat(rows)
					this.listData = newArr;
					this.total = res.data.attributes.total
				} else {
					uni.showToast({
						title:res.data.message,
						icon:'none'
					})
				}
			},
		},
		onLoad() {
			this.getDataList()
		},
		onShow(){
			this.$refs.child.handleClose()
			this.getDataList()
			uni.$on("refreshDataList", res => {
				this.getDataList()
				uni.$off('refreshDataList');
			})
		},
		onPullDownRefresh(){
			console.log('下拉刷新')
			this.getDataList();
			setTimeout(function() {  
				uni.stopPullDownRefresh();  
			}, 1500);  
		},
		onReachBottom(){
			const totalPage = Math.ceil(this.total/10);
			const currPage = this.pageNumber;
			if(currPage < totalPage){
				this.pageNumber ++;
				this.getDataList()
			} else {
				this.moreTip = true
			}
			
		},
		onShareAppMessage() {
			return {
				imageUrl: 'https://www.szaez.com/sck/share.jpg?v=' + new Date().getTime()
			}
		},
	}
</script>
 
<style lang="scss">
	page{
		background-color: #e9f0f2;
	}
	.content-box {
		width: 750rpx;
	
		.nav-wrap {
			width: 750rpx;
			height: 70rpx;
		}
	}
	.goods-list {
		flex-wrap: wrap;
	
		.goods-item {
			margin-right: 20rpx;
			margin-bottom: 20rpx;
	
			&:nth-child(2n) {
				margin-right: 0;
			}
		}
	}
	.popup-content {
		width:680rpx;
		background-color: #fff;
		padding: 20rpx;
		.content-title{
			text-align: center;
		}
		.content-name{
			padding: 40rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
		}
		.check-box{
			padding: 40rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
		}
		.btn-grow{
			padding: 40rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
		}
		.selectBox{
		  background: #EB5248!important;
		  color: #fff!important;
		}
		.checkbox{
		  padding: 5px 10px;
		  border: 1px solid #EB5248;
		  margin: 10px;
		  border-radius: 7upx;
		  color: #000;
		}
	}
</style>
